//快排算法
function quickSort(arr, left, right) {
    if (arr.length > 1) {
        let index = partition(arr, left, right);
        if (left < index - 1) {
            quickSort(arr, left, index - 1);
        }
        if (index < right) {
            quickSort(arr, index, right);
        }
    }
    return arr;
}
function partition(arr, left, right) {
    let pivot = arr[Math.floor((right + left) / 2)];
    while (left <= right) {
        while (arr[left] < pivot) {
            left++;
        }
        while (arr[right] > pivot) {
            right--;
        }
        if (left <= right) {
            swap(arr, left, right);
            left++;
            right--;
        }
    }
    return left;
}
function swap(arr, left, right) {
    let temp = arr[left];
    arr[left] = arr[right];
    arr[right] = temp;
}

console.log(quickSort([3, 2, 1, 4, 5, 6, 7, 8, 9, 10], 0, 9));